package PAT;

import java.util.Scanner;

/**
 * 现给出两人的交锋记录，请统计双方的胜、平、负次数，并且给出双方分别出什么手势的胜算最大。

 输入格式：

 输入第1行给出正整数N（<=105），即双方交锋的次数。随后N行，每行给出一次交锋的信息，即甲、乙双方同时给出的的手势。C代表“锤子”、J代表“剪刀”、B代表“布”，第1个字母代表甲方，第2个代表乙方，中间有1个空格。

 输出格式：

 输出第1、2行分别给出甲、乙的胜、平、负次数，数字间以1个空格分隔。第3行给出两个字母，分别代表甲、乙获胜次数最多的手势，中间有1个空格。如果解不唯一，则输出按字母序最小的解。

 输入样例：
 10
 C J
 J B
 C B
 B B
 B C
 C C
 C B
 J B
 B C
 J J
 输出样例：
 5 3 2
 2 3 5
 B B
 * Created by yang on 2016/11/19.
 * 问题：超时
 */
public class Game {
    private static int winJ = 0;
    private static String mostJ;
    private static int winJC = 0;
    private static int winJJ = 0;
    private static int winJB = 0;
    private static int winY = 0;
    private static String mostY;
    private static int winYC = 0;
    private static int winYJ = 0;
    private static int winYB = 0;
    private static int draw = 0;
    private static int loseJ = 0;
    private static int loseY = 0;
    public void competing() {
        Scanner scanner = new Scanner(System.in);
        int competime = scanner.nextInt();
        for (int i = 0; i < competime; i++) {
            String jia = scanner.next();
            String yi = scanner.next();
            if (jia.equals("J")) {
                if (yi.equals("J")) {
                    draw++;
                }else if (yi.equals("C")) {
                    winY++;
                    winYC++;
                    loseJ++;
                }else if (yi.equals("B")) {
                    winJ++;
                    winJJ++;
                    loseY++;
                }
            }else if (jia.equals("C")) {
                if (yi.equals("C")) {
                    draw++;
                }else if (yi.equals("B")) {
                    winY++;
                    winYB++;
                    loseJ++;
                }else if (yi.equals("J")) {
                    winJ++;
                    winJC++;
                    loseY++;
                }
            }else if (jia.equals("B")) {
                if (yi.equals("B")) {
                    draw++;
                }else if (yi.equals("J")) {
                    winY++;
                    winYJ++;
                    loseJ++;
                }else if (yi.equals("C")) {
                    winJ++;
                    winJB++;
                    loseY++;
                }
            }
        }

        int baseJ = winJ/3 + 1;
        if (winJB >= baseJ) {
            mostJ = "B";
        }else if (winJC >= baseJ) {
            mostJ = "C";
        }else if (winJJ >= baseJ) {
            mostJ = "J";
        }

        int baseY = winY/3 + 1;
        if (winYB >= baseY) {
            mostY = "B";
        }else if (winYC >= baseY) {
            mostY = "C";
        }else if (winYJ >= baseY) {
            mostY = "J";
        }

        System.out.println(winJ+" "+draw+" "+loseJ);
        System.out.println(winY+" "+draw+" "+loseY);
        System.out.print(mostJ+" "+mostY);
    }
}
